<?php

class Zendhlt_Utilities_Utils {

	protected static $instance = NULL;

	/**
	 * Prevent direct object creation
	 */
	final private function  __construct() { }
	final private function  __clone() { }

	public static function singleton()
	{
		if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c;
		}
		return self::$instance;
	}

	public static function substrwords($text, $maxchar, $end = '...') {
		if (strlen($text) > $maxchar || $text == '') {
			$words  = preg_split('/\s/', $text);
			$output = '';
			$i      = 0;
			while (1) {
				$length = strlen($output) + strlen($words[$i]);
				if ($length > $maxchar) {
					break;
				} else {
					$output .= " " . $words[$i];
					++$i;
				}
			}
			$output .= $end;
		} else {
			$output = $text;
		}
		return $output;
	}

}